import os
import json

# 存储所有轨迹保存路径的列表
trajectories_save_paths = [
    "hotpot/trajectories-disable-early-stop_train_Phi-3_lats_20iterations-iteration5",
    "hotpot/trajectories-disable-early-stop_train_Phi-3_lats_20iterations-iteration5",
    # 这里可以添加更多的路径
    # "path/to/another/trajectories_save_path",
]

# 初始化列表以存储结果
best_reward = []
best_em = []
best_child_reward = []
best_child_em = []

# 遍历所有路径
for path in trajectories_save_paths:
    for file in os.listdir(path):
        if not file.endswith('json'):
            continue
        with open(os.path.join(path, file)) as f:
            result = json.load(f)
        best_reward.append(result.get('best reward', 0))  # 使用get方法提供默认值
        best_em.append(result.get('best em', 0) if result.get('best em') is not None else 0)
        best_child_reward.append(result.get('best child reward', 0))
        best_child_em.append(result.get('best child em', 0) if result.get('best child em') is not None else 0)

# 打印结果
print("Total sample number: ", len(best_child_reward))
print("Average best reward: ", sum(best_reward) / len(best_reward))
print("Average best em: ", sum(best_em) / len(best_em))
print("Average best child reward: ", sum(best_child_reward) / len(best_child_reward))
print("Average best child em: ", sum(best_child_em) / len(best_child_em))